<template>
  <div class="mod-config">
      <el-form :inline="true" :model="dataForm"  ref="searchForm" @keyup.enter.native="getDataList">
        <el-row>
          <el-form-item>
            <el-input v-model="dataForm.customerName" placeholder="请输入姓名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary"  @click="getDataList()">查询</el-button>
            <el-button icon="el-icon-delete" @click="searchReset">清空</el-button>
          </el-form-item>
        </el-row>
        <el-row>
          <el-button type="primary" icon="el-icon-plus" @click="openAddForm">新增</el-button>
        </el-row>
      </el-form>

      <div class="avue-crud">
        <el-table :data="dataList" height="calc(100vh - 215px)" border v-loading="dataListLoading">
          <el-table-column prop="registerConfigName" label="挂号项目"></el-table-column>
          <el-table-column prop="price" label="挂号费用"></el-table-column>
          <el-table-column prop="customerName" label="姓名"></el-table-column>
          <el-table-column prop="customerCard" label="卡号"></el-table-column>
          <el-table-column prop="customerPhone" label="电话号码"></el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalPage"
          background
          layout="total, sizes, prev, pager, next">
        </el-pagination>
      </div>

      <!-- 弹窗，  结账 -->
      <payment v-if="paymentVisible" ref='payment' :saleDataList="dataList" @refreshDataList="getDataList"></payment>
  </div>
</template>

<script>
  import {fetchCtgList, delCtgObj, getCtgObj} from '@/api/eims/ctg.js'
  import {fetchMatchingList,delMatchingObj} from '@/api/eims/cashier/payment'
  import {getRegisterCenterPage} from '@/api/eims/cashier/register'

  import Payment from './Payment'

  import {mapGetters} from 'vuex'
  export default {
    data () {
      return {
        dataForm: {
          key: '',
            customerName:''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        paymentVisible: false
      }
    },
    created () {
      this.getDataList()
    },
    computed: {
      ...mapGetters(['permissions','userInfo'])
    },
    components:{
      Payment
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.dataForm.deptId = this.userInfo.lessDeptId
        let params1 = { current: this.pageIndex, size: this.pageSize }
        let params2 = this.filterParams(this.dataForm)
        getRegisterCenterPage(Object.assign(params1,params2)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 搜索清空
      searchReset () {
          this.dataForm = {};
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      //  新增
      openAddForm() {
            this.paymentVisible = true
            this.$nextTick(() => {
                this.$refs.payment.init()
            })
        },
      // 删除
      deleteHandle (id) {
        this.$confirm('是否确认删除ID为' + id, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => {
          return delMatchingObj(id)
        }).then(response => {
          if(response.data.code == '0'){
            this.$message.success('删除成功')
            this.getDataList()
          }else{
            this.$message.error(response.data.msg)
          }
          
        })
      }
    }
  }
</script>
